# 暴力匹配器、ORB描述符和match()方法
import cv2

img1 = cv2.imread("bear.png", cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread("whitebear.png", cv2.IMREAD_GRAYSCALE)

orb = cv2.ORB_create()
kp1, des1 = orb.detectAndCompute(img1, None)
kp2, des2 = orb.detectAndCompute(img2, None)

bf = cv2.BFMatcher_create(cv2.NORM_HAMMING, crossCheck = False)
ms = bf.match(des1, des2)
ms = sorted(ms, key = lambda x:x.distance)
img3 = cv2.drawMatches(img1, kp1, img2, kp2, ms[:20], None, flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)

cv2.imshow("bear", img1)
cv2.imshow("whitebear", img2)
cv2.imshow("Matches", img3)

cv2.waitKey(0)
cv2.destroyAllWindows()
